#ifndef BASEAUDIO_H
#define BASEAUDIO_H

#include <al.h>
#include <alc.h>
#include <alut.h>
#include <map>

enum SoundType
{
	SOUND_BACKGROUND,
	SOUND_FOOTSTEP,
	SOUND_IDLE,
	SOUND_MOVE,
	SOUND_JUMP,
	SOUND_ACTIVATION,
	SOUND_BIGSHOT,
	SOUND_DEATH,
	SOUND_DESINTEGRATE,
	SOUND_GAINREWARD,
	SOUND_HIT1,
	SOUND_HIT2,
	SOUND_LEVELUP,
	SOUND_MENU,
	SOUND_PLAYERMELEE,
	SOUND_PLAYERMELEE2,
	SOUND_PLAYERRANGED,
	SOUND_PLAYERRANGED2,
	SOUND_NERVOUSBG,
	SOUND_BG1,
	SOUND_HUMM,
	SOUND_HUMM2,
	SOUND_LASER,
	SOUND_LIGHT
};

// Cached sound file
struct SoundResource
{
	ALvoid *data;
	ALenum format;
	ALsizei size;
	ALfloat freq;
};

typedef std::map<SoundType, SoundResource> SoundMap;
typedef std::map<ALuint, ALuint> SourceMap;

class BaseAudio
{
public:
	BaseAudio(void);
	virtual ~BaseAudio(void);
	const bool init(void);
	void setListenerPosition(const ALfloat x, const ALfloat y, const ALfloat z);
	void setPosition(const ALuint source, const ALfloat x, const ALfloat y, const ALfloat z);
	void setGlobalVolume(const ALfloat volume);
	const ALfloat getGlobalVolume(void) const;
	const ALuint playSound(const SoundType type, const bool loop);
	void playSound(const ALuint source);
	void stopSound(const ALuint source) const;
	void pauseSound(const ALuint source) const;
	void releaseSound(const ALuint source);
	const bool isPlaying(const ALuint source);
	void setBGMusic(const SoundType type);
	void stopBGMusic(void);
	void update(void);
protected:
	// Load and cache a sound file
	const bool loadSoundFile(const char *filename, const SoundType type);
	// Global volume
	ALfloat mfVolume;
	// Position of the listener
	ALfloat mfListenerXPos;
	ALfloat mfListenerYPos;
	ALfloat mfListenerZPos;
	// Map with all loaded sound files
	SoundMap mSoundMap;
	// Map with all sounds in OpenAL
	SourceMap mSourceMap;
	// Source for playing background music
	ALuint mBGMusic;
};

#endif